package com.mh.www.mh_frame.view.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.mh.www.mh_frame.R;
import com.mh.www.mh_frame.presenter.iview.SplashView;
import com.mh.www.mh_frame.view.activity.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lenovo on 2018/4/12.
 */

public class SplashActivity extends BaseActivity implements SplashView {
    @BindView(R.id.iv_bg)
    ImageView mIvBg;
    @BindView(R.id.pg)
    ProgressBar mPg;
    @BindView(R.id.tv_tip)
    TextView mTvTip;
    @BindView(R.id.title)
    ImageView mTitle;

    @Override
    protected void setContentLayout() {
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);

    }

    @Override
    protected void initView() {
        /**
         * 进度条
         */
        initAnimator();
    }

    @Override
    protected void obtainData() {

    }

    @Override
    protected void initEvent() {

    }

    @Override
    public void initAnimator() {
        ValueAnimator animator = ValueAnimator.ofInt(0, 100);
        //动画时长
        animator.setDuration(3000);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int a = (int) animation.getAnimatedValue();
                //刷新进度条
                mPg.setProgress(a);
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                super.onAnimationCancel(animation);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                //动画结束
                startActivity(LoginActivity.class, true);
            }
        });
        //设置插值器
        animator.setInterpolator(new LinearInterpolator());
        //开始动画
        animator.start();
    }
}
